package cn.zebra.dev.order.module.express.service.impl;

import cn.zebra.dev.ibatis.plus.service.impl.ServiceImpl;
import cn.zebra.dev.ibatis.plus.utils.PageUtils;
import cn.zebra.dev.ibatis.plus.utils.Query;
import cn.zebra.dev.order.module.express.dao.OrdersExpressDao;
import cn.zebra.dev.order.module.express.entity.OrdersExpressEntity;
import cn.zebra.dev.order.module.express.service.OrdersExpressService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 订单物流信息(与订单表一对一)
 *
 * @author runnable
 */
@Service
public class OrdersExpressServiceImpl extends ServiceImpl<OrdersExpressDao, OrdersExpressEntity> implements OrdersExpressService {

    @Override
    public PageUtils<OrdersExpressEntity> findPage(Map<String, Object> params) {
        QueryWrapper<OrdersExpressEntity> wrapper = new QueryWrapper<>();
        IPage<OrdersExpressEntity> page = this.page(
                new Query<OrdersExpressEntity>(params).getPage(),
                wrapper
        );

        return new PageUtils<>(page);
    }

    /**
     * 根据订单号查询订单物流信息
     *
     * @param ordersId 订单表id
     * @return 订单物流信息实体
     */
    @Override
    public OrdersExpressEntity findByOrdersId(Long ordersId) {
        QueryWrapper<OrdersExpressEntity> wrapper = new QueryWrapper<>();
        wrapper.apply("orders_id = {0}", ordersId);
        return this.getOne(wrapper);
    }

    @Override
    public PageUtils<OrdersExpressEntity> findListPage(Map<String, Object> params) {
        Page<OrdersExpressEntity> page = new Query<OrdersExpressEntity>(params).getPage();
        page.setRecords(baseMapper.findListPage(page, params));
        return new PageUtils<>(page);
    }

    @Override
    public OrdersExpressEntity findExpressSn(String expressSn, Long id) {
        QueryWrapper<OrdersExpressEntity> wrapper = new QueryWrapper<>();
        wrapper.select("express_sn");
        wrapper.apply("express_sn = {0}",expressSn);
        wrapper.apply("express_user_id = {0}", id);
        return this.getOne(wrapper);
    }



}
